package com.guoyansoft.controller;

import com.guoyansoft.config.R;
import com.guoyansoft.model.pojo.Address;
import com.guoyansoft.model.pojo.District;
import com.guoyansoft.model.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：zyx
 * @date ：Created in 2023-05-04-19:46
 * @description：
 * @modified By：
 * @version: $
 */
@RestController
@RequestMapping("/district")
public class DistrictController {
    @Autowired
    private DistrictService districtService;

    @RequestMapping("/queryAll")
    public R queryAll() {
        R r = districtService.queryAll();
        return r;
    }
    @RequestMapping("/queryByPage")
    public R queryByPage(String district,Integer curPage,Integer pageSize){
        if(district==null){
            district="";
        }
        Map<String,Object> params=new HashMap<>();
        params.put("districtKey","%"+district+"%");
        params.put("startIndexKey",(curPage-1)*pageSize);
        params.put("pageSizeKey",pageSize);
        R r = districtService.queryByPage(params);
        return r;
    }
    @RequestMapping("/save")
    public R save(District district){
        R save = districtService.save(district);
        return save;
    }
    @RequestMapping("/drop")
    public R drop(Integer[] id){
        R drop = districtService.drop(id);
        return drop;
    }

    @RequestMapping("/update")
    public R update(District district){
        R modify = districtService.update(district);
        return modify;
    }
}
